/**
 * 你可以认为 state 是 store 的数据 (data)，getters 是 store 的计算属性 (computed)，而 actions 则是方法 (methods)。
 */
import _ from 'lodash'
const useSafetyMapStore = defineStore(
  'safety-map',{
    state: () => ({
      defaultAllVehicleIds:[], //默认全部机具ID用于实时数据导出用
      currentSelectVehicleId:'', // 当前选中车辆ID
      opTime:0,
      selectedVehicleIds: [], // 当前选中车辆数据
      selectedVehicleDatas:[], //当前选中车辆详情列表
      tabTableHeight:230,  // 列表内容高度
      selectAreas:[], //电子围栏数据
      poiTabShow:false, // poi tabs 是否可见
      allPois:[], // 全部poi点
      mapCenterLngLat:[], //设置中心点
      ztreeHeight: 707,//车辆树结构ztree高度
      treeEjectHeight: 32, //地图监控车辆信息框高度
      mapVideoListWidth: 0, //地图监控视频盒宽度
      mapInfowWindowBtFlag: '',//地图监控车辆info窗体按钮选中类型
      mapCarEjectFlag: 'status' //地图监控车辆信息框默认选中状态
    }),
    getters: {
      //当前车辆的详情数据
      currentSelectVehicleData: (state) => {
        console.log(123);
        return state.currentSelectVehicleId ? state.selectedVehicleDatas.find((item)=> item.vehicleId == state.currentSelectVehicleId ) : []
      }
    },
    actions: {
      setCurrentSelectVehicleId(id=''){
        this.currentSelectVehicleId = id;
        this.opTime = new Date().getTime();
      },
      setSelectedVehicleIds(ids=[]){
        this.selectedVehicleIds = ids;
      },
      setTabTableHeight(height){
        this.tabTableHeight = height-50;
      },
      setSelectAreas(datas=[]){
        console.log(datas.length)
        if(datas.length>0){
          this.selectAreas = _.concat(this.selectAreas,datas)
          this.selectAreas = _.uniqBy(this.selectAreas,'id')
        }
      },
      delSelectAreasRow(index){
        this.selectAreas.splice(index, 1)
      },
      delAllAreasRow(){
        this.selectAreas =[]
      },
      setPoiTabShow(flag){
        this.poiTabShow = flag
      },
      setAllPois(datas=[]){
        this.allPois = datas
      },
      setMapCenterLngLat(lng,lat){
        this.mapCenterLngLat=[lng,lat]
      },
      setSelectedVehicleDatas(datas=[]){
        this.selectedVehicleDatas = datas == null ? [] : datas;
      },
      setDefaultAllVehicleIds(datas=[]){
        this.defaultAllVehicleIds = datas == null ? [] : datas;
      },
      setMapVideoListWidth(width){
        this.mapVideoListWidth = width;
      },
      setTreeEjectHeight(height){
        this.treeEjectHeight = height;
      },
      setZtreeHeight(height){
        this.ztreeHeight = height;
      },
      setMapCarEjectFlag(flag){
        this.mapCarEjectFlag = flag;
      },
      setMapInfowWindowBtFlag(flag){
        this.mapInfowWindowBtFlag = flag;
      },
    }
  })

export default useSafetyMapStore
